package com.treasure.service.creditCard.controller;

import java.io.UnsupportedEncodingException;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.treasure.service.dto.TApplyCardOrderDto;
import com.treasure.service.result.PageResult;
import com.treasure.service.result.ResponseResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import com.treasure.service.annotation.LogInfo;
import com.treasure.service.domain.TApplyCardOrder;
import com.treasure.service.creditCard.service.OrderService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;

/**
* @Description:    订单
* @Author:         panxinwen
* @CreateDate:     2018/10/15 21:13
* @Version:        1.0
*/
@Api(value = "订单",description = "订单相关操作")
@RestController
@RequestMapping("/order/v1")
public class OrderController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private OrderService orderService;

    @LogInfo(log = "创建信用卡订单",isPrint = true)
    @PostMapping("/createCardOrder")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "openId", value = "用户在公众号唯一编号", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "realName", value = "姓名", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "certNo", value = "证件号", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "mobile", value = "手机号", required = false, dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "bankCode", value = "银行编码", required = false, dataType = "String", paramType = "query"),
    })
    public ResponseEntity createCardOrder(@RequestBody TApplyCardOrderDto applyCardOrder) throws UnsupportedEncodingException {
        logger.info("创建信用卡订单参数：{}",JSON.toJSONString(applyCardOrder));
        ResponseResult responseResult =orderService.createApplyCardOrder(applyCardOrder);
        return  ResponseEntity.ok(responseResult);

    }

    @LogInfo(log = "获取我的订单",isPrint = true)
    @PostMapping("/getCardOrderList")
    @ApiImplicitParams({})
    public ResponseEntity getCardOrderList(@RequestParam(value = "pageSize") Integer pageSize,
                                           @RequestParam(value = "pageNum") Integer pageNum,
                                           @RequestParam(value = "param",required = false) String param,
                                           @RequestParam(value = "userId") Long userId) throws UnsupportedEncodingException {
        PageResult<List<TApplyCardOrderDto>> result = orderService.getCardOrderList(pageSize,pageNum,userId,param);

        return  ResponseEntity.ok(result);

    }

    @LogInfo(log = "获取订单详情",isPrint = true)
    @PostMapping("/getOrderMsg")
    @ApiImplicitParams({})
    public ResponseEntity getOrderMsg(@RequestParam(value = "orderId") Long orderId) throws UnsupportedEncodingException {

        TApplyCardOrderDto result = orderService.getOrderMsg(orderId);

        return  ResponseEntity.ok(result);

    }

}
